﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeGen.TS.Generation.Members
{
    public static class IMemberInfoExtensions
    {
        public static string GetTypeName(this IMemberInfo info)
        {
            string tsType = null, knockoutType = null;
            switch (info.ScriptType)
            {
            case IntegratedTypescriptType.Bool:
                    
                    tsType = "bool";
                    knockoutType = "KnockoutObservableBool";
                    break;
                case IntegratedTypescriptType.Number:
                    
                    tsType = "number";
                    knockoutType = "KnockoutObservableNumber";
                    break;
                case IntegratedTypescriptType.String:
                   
                    tsType = "string";
                    knockoutType = "KnockoutObservableString";
                    break;
                case IntegratedTypescriptType.Date:
                    
                    tsType = "Date";
                    knockoutType = "KnockoutObservableDate";
                    break;
                case IntegratedTypescriptType.Complex:
                    {

                        tsType = knockoutType = info.ComplexTypeName;
                    }
                    break;
                case IntegratedTypescriptType.Unknown:
                   
                    tsType = "any";
                    knockoutType = "KnockoutObservableAny";
                    break;
            }
            if (tsType == null || knockoutType == null)
                throw new ArgumentException("Unknown Typescript Type");
            if (info.IsArray)
            {
                tsType += "[]";
                knockoutType = "KnockoutObservableArray";//Maybe one could extend this
            }
            if (info.UseObservable)
            {
                return knockoutType;
            }
            else
            {
                return tsType;
            }
        }
    }
}
